home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / mnpc12.zip / FCSCALC.ASM < prev    next >
Assembly Source File  |  1987-11-16  |  2KB  |  98 lines

  1.     title    fcscalc.asm
  2.     page    60,132
  3. ;==============================================================================
  4. ;
  5. ;                     The Microcom MNP Library
  6. ;                    (Microsoft C Version)
  7. ;
  8. ;------------------------------------------------------------------------------
  9. ;
  10. ;    fcscalc - calculate frame check sequence
  11. ;
  12. ;    synopsis: 
  13. ;        
  14. ;            fcscalc(fcs_word,octet);
  15. ;
  16. ;    input:
  17. ;            struct {char low, hi;}  *fcs_word;
  18. ;            char octet;
  19. ;
  20. ;==============================================================================
  21.  
  22. _data     segment word public 'DATA'
  23. _data    ends
  24. dgroup    group    _data
  25.  
  26. _data    segment 
  27. temp    db    ?            ; temp variable
  28. _data    ends
  29.  
  30. _text    segment byte public 'CODE'
  31.     assume     cs:_text,ds:dgroup
  32.  
  33.     public    _fcscalc
  34.  
  35. fcs    =    4
  36. octet    =    6
  37. hi    =    1
  38. ;
  39. ;
  40. _fcscalc proc    near
  41.  
  42.     push    bp
  43.     mov    bp,sp
  44. ;
  45.     push    ax
  46.     push    bx
  47.     push    cx
  48.     push    si
  49. ;
  50.     mov    ax,[bp+octet]    ;get octet
  51.     mov    si,[bp+fcs]
  52.     xor    al,[si+hi]    ;hi byte of resulting fcs number
  53.     mov    temp,al
  54.     mov    bl,al
  55. ;
  56.     mov    cx,7
  57. lp1:    sar    bl,1
  58.     add    al,bl
  59.     loop    lp1
  60. ;
  61.     and    al,01h
  62.     mov    bl,temp
  63.     sar    al,1
  64.     rcr    bl,1
  65.     rcr    al,1
  66.     sar    bl,1
  67.     rcl    bl,1
  68.     pushf            ;save carry flag
  69.     xor    bl,temp
  70.  
  71. ;    popf            ;recover carry flag
  72.     jmp    $+3            ; simulate popf
  73.     iret
  74.     push    cs
  75.     call    cs:$-2
  76.  
  77.     rcr    bl,1
  78.     rcr    al,1
  79.     sar    bl,1
  80.     rcl    bl,1
  81.     adc    al,00h
  82.     xor    al,[si]     ;low byte of resulting fcs number
  83.     mov    [si],bl     ;save new low byte
  84.     mov    [si+hi],al    ;save new hi byte
  85. ;
  86.     pop    si
  87.     pop    cx
  88.     pop    bx
  89.     pop    ax
  90. ;
  91.     pop    bp
  92.     ret
  93. ;
  94. _fcscalc endp
  95.  
  96. _text    ends
  97.     end
  98.